package com.cmft.generator.utils;

import com.cmft.demo.DemoEntity;
import org.apache.commons.lang.StringUtils;

import java.lang.reflect.Method;

public class BeanUtils {

    public static void setterPrint(String objName, Class<?> objClass) {
        for (Method method : objClass.getDeclaredMethods()) {
            if (!method.getName().startsWith("set")) {
                continue;
            }
            System.out.println(objName + "." + method.getName() + "();");
        }
    }

    /**
     * 首字母大写
     *
     * @param fieldName
     * @return
     */
    public static String firstUpper(String fieldName) {
        return fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
    }

    /**
     * 首字母小写
     *
     * @param fieldName
     * @return
     */
    public static String firstLower(String fieldName) {
        return fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
    }

    /**
     * 砣峰
     *
     * @param str
     * @return
     */
    public static String tuoFeng(String str) {
        if (str.indexOf('_') == -1) {
            return str.toLowerCase();
        }
        String[] arr = str.split("_");
        StringBuilder value = new StringBuilder();
        for (String tmp : arr) {
            if (StringUtils.isEmpty(tmp)) {
                continue;
            }
            value.append(tmp.substring(0, 1).toUpperCase()).append(tmp.substring(1).toLowerCase());
        }
        String result = value.toString();
        return result.substring(0, 1).toLowerCase() + result.substring(1);
    }

    public static void main(String[] args) {
        setterPrint("demo", DemoEntity.class);
    }
}
